package com.cms.room

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

/**
 * @author: Mr.You
 * @create: 2022-10-10 16:30
 * @description:
 **/
class RoomViewModel(application: Application) :AndroidViewModel(application) {
    private  var dataBase: StudentDataBase

    init {
        dataBase = StudentDataBase.getStudentDataBase(application)
    }
    fun insertStudent(vararg student: Student){
        dataBase.studentDao().insertStudent(*student)
    }
    fun deleteStudent(student: Student){
        dataBase.studentDao().deleteStudent(student)
    }
    fun updateStudent(student: Student){
        dataBase.studentDao().updateStudent(student)
    }
    fun queryStudent(): LiveData<List<Student>> {
      return dataBase.studentDao().getStudents()
    }


}